/* 
 * File:   semaphore.h
 * Author: Brian
 *
 * Created on November 16, 2011, 8:04 PM
 */

#ifndef SEMAPHORE_H
#define	SEMAPHORE_H

typedef struct
{
    int state[100];                  // semaphore state
    
    // In and out variables for the wait queue
    int in,out;
    int queue[100][10];
} SEMAPHORES;


/*
 * Initialize the semaphores to 1.
 */
void initiateSemaphores(SEMAPHORES *semaphores);

/*
 * Check if any process is waiting.
 */
int anyWaiting(SEMAPHORES *semaphores, int semaphore);

/*
 * Check if a specific process is waiting.
 */
int isWaiting(SEMAPHORES *semaphores, int semaphore, int process);


/*
 * Method for pushing processes on the semaphore wait queue.
 */
void pushProcess(SEMAPHORES *stack, int semaphore, int item);

/*
 * Method to pop the last process off the semaphore wait queue.
 */
int popProcess(SEMAPHORES *stack, int semaphore);

#endif	/* SEMAPHORE_H */
